package ai.george.ai.controller.google;


import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.chat.client.advisor.SimpleLoggerAdvisor;
import org.springframework.ai.chat.model.ChatResponse;
import org.springframework.ai.vertexai.gemini.VertexAiGeminiChatModel;
import org.springframework.ai.vertexai.gemini.VertexAiGeminiChatOptions;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/gemini-chat-client")
public class GeminiChatClientController {


    private static final String DEFAULT_PROMPT = "你是一个博学的智能聊天助手，请根据用户提问回答！";

    private final ChatClient dashScopeChatClient;


    /**
     * 使用构造器注入ChatClient
     */
    public GeminiChatClientController(VertexAiGeminiChatModel openAiChatModel) {
        VertexAiGeminiChatOptions chatOptions = VertexAiGeminiChatOptions.builder()
                .model("gemini-2.0-flash")
                .temperature(0.7)
                .build();

        this.dashScopeChatClient = ChatClient.builder(openAiChatModel)
//                .defaultSystem(DEFAULT_PROMPT)
                // 实现 Logger 的 Advisor
                .defaultAdvisors(
                        new SimpleLoggerAdvisor()
                )
                // 设置 ChatClient 中 ChatModel 的 Options 参数
                .defaultOptions(chatOptions)
                .build();
    }

    /**
     * ChatClient 简单调用
     */
    @GetMapping("/text")
    public String simple(@RequestParam(value = "query", defaultValue = "你好，很高兴认识你，能简单介绍一下自己吗？") String query) {

        String content = dashScopeChatClient
                .prompt()
                .system(DEFAULT_PROMPT)
                .user(query)
                .call()
                .content();
        return content;
    }


    @GetMapping("/chat-response")
    public ChatResponse chatResponse(@RequestParam(value = "query", defaultValue = "你好，很高兴认识你，能简单介绍一下自己吗？") String query) {
        ChatResponse chatResponse = dashScopeChatClient
                .prompt()
                .system(DEFAULT_PROMPT)
                .user(query)
                .call()
                .chatResponse();
        return chatResponse;
    }








}
